﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

/// <summary>
/// Summary description for clsMenu
/// </summary>
public class clsMenu
{
	public clsMenu()
	{
		
	}
    public string taoMenu()
    { 
        clsTableAction clsTable = new clsTableAction("Menu");
        SqlDataReader sqlDare = clsTable.exportDataReader("*", " parent = 0");

        string listMenu = "<dl>";
        while (sqlDare.Read())
        {
            if (listMenu.Length == 4)
                listMenu = listMenu + "<dt><a class='active' href='#'>" + sqlDare[2].ToString() + "</a></dt>";
            else
                listMenu = listMenu + "<dt><a href='#'>" + sqlDare[2].ToString() + "</a></dt>";
            listMenu = listMenu + taoSubMenu(sqlDare[0].ToString());
        }
        clsTable.free();
        return listMenu;
    }
    private string taoSubMenu(string id)
    {
        clsTableAction clsTable = new clsTableAction("Menu");
        SqlDataReader sqlDare = clsTable.exportDataReader("*", " parent = " + id.ToString());

        string listMenu = "<dd><ul>";
        while (sqlDare.Read())
        {
            listMenu = listMenu + "<li><a href='listFilter.aspx?func=" + sqlDare[0].ToString() + "'>" + sqlDare[2].ToString() + "</a></li>";
        }
        listMenu = listMenu + "</ul></dd>";
        clsTable.free();
        return listMenu;
    }

    public void exportDataToDropDownList(ref DropDownList drop)
    {
        clsTableAction clsTable = new clsTableAction("menu");
        SqlDataReader sqlDare = clsTable.exportDataReader("lableVI,ID_MN", " parent<>0");
        drop.DataSource = sqlDare;
        drop.DataTextField = "lableVI";
        drop.DataValueField = "ID_MN";
        drop.DataBind();
        clsTable.free();
    }


}
